
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int f1 = 0;
        int f2 = 1;
        int f3 = 0;
        while (f2 <= n) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        int left = n- f1;
        int right = f2 -n;
        if (left < right) {
            System.out.println(left);
        }else {
            System.out.println(right);
        }
    }
}